package org.origin.ferret.center.model.base;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Column;
import io.swagger.v3.oas.annotations.media.Schema;
import org.origin.centre.utils.UserUtil;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * 基础数据模型
 *
 * @author ferret
 * @version 2024-05-08
 */
@SuppressWarnings(value = {"unused"})
public abstract class BasicEntity {

    @Schema(description = "创建人ID")
    private String createBy;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Schema(description = "更新人ID")
    private String updateBy;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;    // 更新时间

    @Column(isLogicDelete = true)
    @Schema(description = "逻辑删除标记（0.正常--默认；1.删除）")
    private Integer delFlag;

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Integer getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(Integer delFlag) {
        this.delFlag = delFlag;
    }

    public void preInsert() {
        this.setCreateTime(new Date());
        this.setUpdateTime(this.getCreateTime());
        this.setCreateBy(UserUtil.getUserId());
        this.setUpdateBy(this.getCreateBy());
    }

    public void preUpdate() {
        this.setUpdateTime(new Date());
        this.setUpdateBy(UserUtil.getUserId());
    }
}
